import React, { useEffect, useState } from 'react';
import { Form, Input, Table } from 'antd';
import { history } from 'umi';
import './lotteryWhiteList.less';
import { whiteListApi } from '@/api/createActivity.js';
export default function () {
  const [tableData, setTableData] = useState([]);
  const columns = [
    {
      title: '活动名称',
      dataIndex: 'activityName',
      key: 'activityName',
    },
    {
      title: '活动状态',
      dataIndex: 'activityStatus',
      key: 'activityStatus',
      render: (_, { activityStatus }) => {
        return (
          <div>
            {activityStatus == 1
              ? '待审核'
              : activityStatus == 2
              ? '进行中'
              : activityStatus == 3
              ? '未开始'
              : activityStatus == 4
              ? '已驳回'
              : activityStatus == 5
              ? '已结束'
              : ''}
          </div>
        );
      },
    },
    {
      title: '抽奖活动时间',
      dataIndex: 'activityTime',
      key: 'activityTime',
    },
    {
      title: '公开方式',
      dataIndex: 'isEveryoneExpose',
      key: 'isEveryoneExpose',
      render: (_, { isEveryoneExpose }) => {
        return <div>{isEveryoneExpose ? '所有人' : '白名单用户'}</div>;
      },
    },
    {
      title: '操作',
      dataIndex: 'operation',
      key: 'operation',
      render: (_, { activityBasicId }) => {
        return (
          <div
            style={{
              marginRight: '5px',
              cursor: 'pointer',
              color: '#4ea3ff',
            }}
            onClick={() => {
              history.push({
                pathname: '/home/lotteryWhiteList/setWhiteList',
                query: { activityBasicId: activityBasicId },
              });
            }}
          >
            设置白名单
          </div>
        );
      },
    },
  ];

  useEffect(() => {
    initialize();
  }, []);
  const initialize = async () => {
    const res = await whiteListApi({
      activityName: '',
      activityState: 1,
      page: 1,
      pageSize: 10,
    });
    console.log(res);
    if (res.data.code == 200) {
      let b = res.data.data.rows.map((item) => {
        return {
          ...item,
          key: item.id,
          activityTime: item.startDate + '-' + item.endDate,
        };
      });
      console.log(b);
      setTableData(b);
    }
  };
  return (
    <div>
      <div className="white-all">
        <div>
          <Table pagination={false} columns={columns} dataSource={tableData} />
        </div>
      </div>
    </div>
  );
}
